/*
 * Copyright 2002-2006 the original author or authors. Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language governing permissions and limitations under the
 * License.
 */
package pikes.html.xhtml;

import pikes.xml.XMLTag;

/**
 * Factory for creating {@link XMLTag} objects. The aim is to provide a way to enforce XML tag rules with Java classes.
 * TagFactory holds the information about the tag's name, the possible attributes and possible child content.<br>
 * The name can be set in getName.<br>
 * The attributes and content of the newly created XML tag is determined by the decoration in the sub classes.
 * @author Peter Bona
 */
public abstract class TagFactory {

	/**
	 * Creates a new XML tag instance with the name from <code>getName</code>. Attributes and content can be added in
	 * <code>decorateCreatedTag</code> method.
	 * @return the newly created XML tag
	 */
	final public XMLTag createTag() {
		XMLTag tag = new XMLTag(getTagName());
		decorateCreatedTag(tag);
		return tag;
	}

	/**
	 * @return the name of the tag
	 */
	abstract protected CharSequence getTagName();

	/**
	 * Add attributes and child content to the newly created tag. Override this to enforce rules on the newly created
	 * tag's content and attributes. By default, this method does not alter the tag.
	 * @param tag the newly created tag
	 */
	protected void decorateCreatedTag(XMLTag tag) {
		// left intentionally empty, this method does nothing by default
	}
}
